package com.hongsheng.util;

/*
@Author：郭振文
@Package：com.hongsheng.config
@File：UserSqlProvider
@Date：2023/8/17 15:23
*/

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class UserSqlProvider {
    public static String getUserByCondition(@Param("name") String name,
                                             @Param("sex") Integer sex,
                                             @Param("address") String address,
                                             @Param("status") Integer status) {
        return new SQL() {{
            SELECT("*");
            FROM("tb_user");
            if (name != null && !name.isEmpty()) {
                WHERE("name like #{name}");
            }
            if (sex!=null){
                WHERE("sex = #{sex}");
            }
            if (address != null && !address.isEmpty()) {
                WHERE("address like #{address}");
            }
            if (status != null) {
                WHERE("status = #{status}");
            }
        }}.toString();
    }
}
